package net.hualisheng.netty.process;


import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Processor {
    public static final ExecutorService service = Executors.newFixedThreadPool(16);

    public void process(SelectionKey key) {
        service.submit(() -> {
            ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
            SocketChannel socketChannel = (SocketChannel) key.channel();
            try {
                int count = socketChannel.read(byteBuffer);
                if (count < 0) {
                    socketChannel.close();
                    key.cancel();
                    return null;
                } else if (count == 0) {
                    return null;

                }
                return String.valueOf(count);

            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return null;

        });
    }
}
